package com.ccp.dev.workflow.configuration;

import com.ccp.dev.WorkflowApplication;
import com.ccp.dev.core.basic.engine.GroovyScriptEngine;
import com.ccp.dev.core.jms.IMessageHandler;
import com.ccp.dev.system.dao.SysUserDao;
import com.ccp.dev.system.service.SysUserService;
import com.ccp.dev.system.service.jms.impl.InnerMessageHandler;
import com.ccp.dev.workflow.bpmimpl.skipimpl.ApproveUserSkipCondition;
import com.ccp.dev.workflow.bpmimpl.skipimpl.GlobalSkipCondition;
import com.ccp.dev.workflow.bpmimpl.skipimpl.SameUserSkipCondition;
import com.ccp.dev.workflow.bpminterface.ISkipCondition;
import com.ccp.dev.workflow.model.ActDefModel;
import com.ccp.dev.workflow.service.bpm.BpmNodeUserCalculationSelector;
import com.ccp.dev.workflow.service.bpm.IBpmNodeUserCalculation;
import com.ccp.dev.workflow.service.bpm.impl.*;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * ClassDescribe:配置流程部分需要的bean
 *
 * @author :jiayueqiao
 * Date: 2019-05-23
 * Since:1
 * To change this template use File | Settings | File Templates.
 */
@Configuration
public class BpmBeansConfiguration {

    @Bean
    public SameUserSkipCondition sameUserSkipCondition(){
        return new SameUserSkipCondition();
    }
    @Bean
    public GlobalSkipCondition globalSkipCondition(){
        return new GlobalSkipCondition();
    }
    @Bean
    public ApproveUserSkipCondition approveUserSkipCondition(){
        return new ApproveUserSkipCondition();
    }

    @Bean
    public Map skipConditionMap(SameUserSkipCondition sameUserSkipCondition,
                                GlobalSkipCondition globalSkipCondition,
                                ApproveUserSkipCondition approveUserSkipCondition){
        Map<String,ISkipCondition> map = new LinkedHashMap();
        map.put(ActDefModel.SKIPSETTING_GLOBAL,globalSkipCondition);
        map.put(ActDefModel.SKIPSETTING_SAMEUSER,sameUserSkipCondition);
        map.put(ActDefModel.SKIPSETTING_APPROVEUSER,approveUserSkipCondition);
        return map;
    }


    @Bean
    public InnerMessageHandler innerMessageHandler(){
        return new InnerMessageHandler();
    }

    @Bean
    public Map handlersMap(InnerMessageHandler innerMessageHandler){
        Map<String,IMessageHandler> map = new LinkedHashMap();
        map.put("1",innerMessageHandler);
        return map;
    }

    @Bean
    public BpmNodeUserCalculationSelector bpmNodeUserCalculationSelector(BpmNodeUserCalculationUser bpmNodeUserCalculationUser, BpmNodeUserCalculationStartUser bpmNodeUserCalculationStartUser, BpmNodeUserCalculationStartOrPrevWithOrg bpmNodeUserCalculationStartOrPrevWithOrg,
    BpmNodeUserCalculationRole bpmNodeUserCalculationRole, BpmNodeUserCalculationOrg bpmNodeUserCalculationOrg,BpmNodeUserCalculationSameNodeDepartment bpmNodeUserCalculationSameNodeDepartment,BpmNodeUserCalculationSameNode bpmNodeUserCalculationSameNode
    ,BpmNodeUserCalculationScript bpmNodeUserCalculationScript,BpmNodeUserCalculationPersonScript bpmNodeUserCalculationPersonScript){
        BpmNodeUserCalculationSelector bpmNodeUserCalculationSelector = new BpmNodeUserCalculationSelector();
        Map<String, IBpmNodeUserCalculation> bpmNodeUserCalculation = new LinkedHashMap<>();
        bpmNodeUserCalculation.put("startUser",bpmNodeUserCalculationStartUser);
        bpmNodeUserCalculation.put("users",bpmNodeUserCalculationUser);
        bpmNodeUserCalculation.put("role",bpmNodeUserCalculationRole);
        bpmNodeUserCalculation.put("org",bpmNodeUserCalculationOrg);
        bpmNodeUserCalculation.put("startOrPrevWithOrg",bpmNodeUserCalculationStartOrPrevWithOrg);
        bpmNodeUserCalculation.put("script",bpmNodeUserCalculationScript);
        bpmNodeUserCalculation.put("personScript",bpmNodeUserCalculationPersonScript);
        bpmNodeUserCalculation.put("sameNode",bpmNodeUserCalculationSameNode);
        bpmNodeUserCalculation.put("sameNodeDepartment",bpmNodeUserCalculationSameNodeDepartment);
        bpmNodeUserCalculationSelector.setBpmNodeUserCalculation(bpmNodeUserCalculation);
        return bpmNodeUserCalculationSelector;
    }

}
